<template>
  <div>
    <!-- 校验签名弹出层 -->
    <dialogPublic
      :title="verifyDialogConfig.title"
      :show.sync="verifyDialogConfig.showVerify"
      @doSubmit="verifyDialogConfig.submit"
      @doClose="verifyDialogConfig.cancel"
      width="500px"
    >
      <!-- 需要填审批意见等信息 -->
      <el-form ref="repeatApprove" label-width="180px">
        <el-form-item label="监护人：" required align="left">
          <el-button
            @click="openSign('showSignGuardian')"
            v-if="showSignGuardian"
            >签名</el-button
          >
          <span>{{ guardianName }}</span>
        </el-form-item>
        <el-form-item label="监护人是否值班负责人：" required align="left">
          <el-radio-group v-model="radioDuty">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="值班负责人签名："
          required
          v-if="radioDuty === 0"
          align="left"
        >
          <el-button @click="openSign('showDutyMan')" v-if="showDutyMan"
            >签名</el-button
          >
          <span>{{ dutyManName }}</span>
        </el-form-item>
        <el-form-item label="复审结果：" required align="left">
          <el-radio-group v-model="radioPass">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="0">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="意见：">
          <el-input type="textarea" v-model="optionTextarea"></el-input>
        </el-form-item>
      </el-form>
    </dialogPublic>
    <signature
      v-if="showSignature"
      @doSign="doSign"
      :showSignature.sync="showSignature"
    ></signature>
  </div>
</template>
<script>
import { toApprove } from "@/api/twoTicketManagement/operationTicket.js";
import signature from "@/components/signature";
export default {
  components: {
    signature,
  },
  props: {
    verifyDialogConfig: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      //签名弹出层
      showSignature: false,
      radioDuty: 1,
      radioPass: 1,
      dutyMan: "",
      dutyManName: "",
      guardian: "",
      guardianName: "",
      optionTextarea: "",
      //控制签名按键显示
      curClickBtn: null,
      showSignGuardian: true,
      showDutyMan: true,
    };
  },
  methods: {
    openSign(btnType) {
      this.curClickBtn = btnType;
      this.showSignature = true;
    },
    async doSign(userInfo) {
      const { account, name } = userInfo;
      if (account) {
        if (this.curClickBtn === "showSignGuardian") {
          this.showSignGuardian = false;
          this.guardianName = name;
          this.guardian = account;
        }

        if (this.curClickBtn === "showDutyMan") {
          if (account !== this.guardian) {
            this.showDutyMan = false;
            this.dutyManName = name;
            this.dutyMan = account;
          } else {
            this.$message.error("值班负责人不能是监护人！！");
          }
        }
      }
    },

    //校验数据
    async checkVerify() {
      let { formId } = this.verifyDialogConfig;
      let params = { id: formId };
      this.radioPass == 0 ? (params.submitType = 2) : (params.submitType = 1);
      params.nowStatus = this.verifyDialogConfig.nowStatus;
      params.opinion = this.optionTextarea;
      if (this.radioDuty === 1) {
        params.dutyMan = this.guardian;
        params.dutyManName = this.guardianName;
        params.guardian = this.guardian;
        params.guardianName = this.guardianName;
        params.isDuty = this.radioDuty;
      } else {
        params.dutyMan = this.dutyMan;
        params.dutyManName = this.dutyManName;
        params.guardian = this.guardian;
        params.guardianName = this.guardianName;
        params.isDuty = this.radioDuty;
      }
      //检查必填项
      if (
        this.guardianName === "" ||
        (this.radioDuty == 0 && this.dutyManName === "")
      ) {
        this.$message.error("请完成签名后再点击确定！");
      } else {
        let res = await toApprove(params);
        this.verifyDialogConfig.cancel();
        return res;
      }
    },
  },
};
</script>